package com.gaga.console.base.config;

/**
 * @DESCRIPTION:
 * @USER: ningxiang
 * @DATE: 5/2/2025 10:35 PM
 */

import com.gaga.common.enums.LiveRoomStatusType;
import com.gaga.console.core.service.BvAudioPlayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ShutdownEventListener implements ApplicationListener<ContextClosedEvent> {

    @Autowired
    private BvAudioPlayService bvAudioPlayService;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        // 执行清理操作
        log.error("应用即将关闭，清理资源...");
        releaseResources();
    }

    private void releaseResources() {
        bvAudioPlayService.setLiveStatus(LiveRoomStatusType.stop);
    }
}